package com.example.transaction.transaction.dao;

import com.example.transaction.transaction.pojp.Account;
import com.example.transaction.transaction.service.AccountService;
import com.example.transaction.transaction.service1.AccountService1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: AccountServiceImpl
 * @DESCRIPT: TODO
 * @AUTHOR: lemontree
 * @DATA: 2020/7/23 9:23 PM
 **/
@Service
@Transactional(propagation = Propagation.REQUIRED)
public class AccountServiceImpl implements AccountService {

    @Autowired
    private AccountService1 service1;

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public void save(Account account) {
        String sql = "insert into account (name,money) values (?,?)";
        List<Object> list = new ArrayList<>();
        list.add(account.getName());
        list.add(account.getMoney());
        jdbcTemplate.update(sql,list.toArray());
        try {
            service1.delete(15);
        }catch (Exception e){
            e.printStackTrace();
        }
        int a = 1/0;
    }
}
